import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

public class CardList {
    public String[] cards={"♥","♠","♣","♦"};//创建一个数组，便于实例化一张牌
    public List<Card> buyCard(){
        List<Card> cardList=new ArrayList<>();//存放所有的牌
        for (int i = 0; i < cards.length; i++) {
            for (int j = 1; j <=13; j++) {
                Card card=new Card(cards[i],j);
                cardList.add(card);//将每张实例化的牌添加到数组中
            }
        }
        return cardList;
    }
    public List<Card> shuffle(List<Card> ret){
        Random random=new Random();//随机数
        for (int i = ret.size()-1; i>0; i--) {
            int index=random.nextInt(i);//产生0-(i-1)随机数
            swap(ret,i,index);//将i下标的牌与index下标的牌进行交换
        }
        return ret;
    }
    public void swap(List<Card> cardList,int i,int index){
        Card tmp=cardList.get(i);//定义中间变量tmp
        cardList.set(i,cardList.get(index));
        cardList.set(index,tmp);
    }
    public List<List<Card>> getCardList(List<Card> ret){
        List<Card> hand1=new ArrayList<>();//玩家1，hand1
        List<Card> hand2=new ArrayList<>();//玩家2，hand2
        List<Card> hand3=new ArrayList<>();//玩家3，hand3
        List<List<Card>> hand=new ArrayList<>(3);
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);
        for (int i = 0; i <5; i++) {
            for (int j = 0; j < hand.size(); j++) {
                Card card=ret.remove(0);//获得第一张牌，并移除
                hand.get(j).add(card);//j下标的人拿到牌
            }
        }
        return hand;

    }


}
